package com.iostream;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;

/**
 * @Author WaveHi
 * @Date 20/8/2021 下午 2:32
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description Test the use of java.io.FileReader
 */
public class TestFileReader {

    public static void main(String[] args) {
        FileReader fr1 = null;

        try {
            //获取流
            fr1 = new FileReader(new File("day11/txt/hello.txt"));

            //读取文件数据
            //接收数据
            StringBuilder sb = new StringBuilder();
            char[] cbuf = new char[10];
            int len = 0;
            while((len = fr1.read(cbuf)) != -1) {

                sb.append(cbuf,0,len);

            }

            //打印数据
            System.out.println(sb);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                //关闭资源
                fr1.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }



    }

}
